package com.lmf.annotation.config;

import com.lmf.annotation.bean.Person;
import com.lmf.annotation.bean.User;
import com.lmf.annotation.controller.MyController;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

/**
 * 验证：自定义过滤类型 使用的配置类
 *  excludeFilters，includeFilters的作用范围：
 *              只扫描通过@Component,@Repository,@Service,@Controller注解注册的各种类，其他方式注册的不会起作用。
 *
 *  过滤方式：
 *     第一种： FilterType.ANNOTATION: 只是扫描 注解类 时，起过滤作用，其他方式注册的不会过滤
 *     第二种： FilterType.ASSIGNABLE_TYPE: 只可以扫描 自定义类 ，~
 *     第三种： FilterType.ASPECTJ: 按照ASPECTJ表达式进行包含或者排除
 *     第四种： FilterType.REGEX: 按照正则表达式进行包含或者排除
 *     第五种： FilterType.CUSTOM: 按照自定义规则进行包含或者排除
 */
@Configuration

//第一种：FilterType.ANNOTATION
//@ComponentScan(value = "com.lmf.annotation", excludeFilters = {
//        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class, Service.class})
//})

//@ComponentScan(value = "com.lmf.annotation",excludeFilters = {
//        @ComponentScan.Filter(type=FilterType.ANNOTATION,classes = {Repository.class})
//})

//@ComponentScan(value = "com.lmf.annotation",useDefaultFilters = false, includeFilters = {
//        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class})
//})
//@ComponentScan(value = "com.lmf.annotation",useDefaultFilters = false, includeFilters = {
//        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Service.class})
//})

//@ComponentScans(value = {
//        @ComponentScan(value = "com.lmf.annotation",useDefaultFilters = false, includeFilters = {
//                @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Service.class})
//        }),
//        @ComponentScan(value = "com.lmf.annotation",useDefaultFilters = false, includeFilters = {
//                @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class})
//        })
//})

//第二种： FilterType.ASSIGNABLE_TYPE
//@ComponentScans(value = {
//        @ComponentScan(value = "com.lmf.annotation",excludeFilters = {
//                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,classes = {User.class, MyController.class})
//        }),
//        @ComponentScan(value = "com.lmf.annotation",useDefaultFilters = false,includeFilters = {
//                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,classes = {User.class, MyController.class})
//        })
//})

//第五种： FilterType.CUSTOM
@ComponentScans(value = {
        @ComponentScan(value = "com.lmf.annotation",useDefaultFilters = false,includeFilters = {
                @ComponentScan.Filter(type = FilterType.CUSTOM,classes = {MyTypeFilter.class})
        })
})


public class MyConfig {
    /**
     *  @Bean：将方法的返回值，注册到spring容器中。id注册名默认是方法名。
     *  注意：也可以使用 @Bean(value = "id注册名")，来修改 id注册名
     * @return
     */
//    @Bean(value = "student")
    @Bean
    public Person person(){
        return new Person("李四",22);
    }
}
